package com.example.config;


import com.example.interceptor.ReqInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private ReqInterceptor reqInterceptor;

    public WebConfig(){
        System.out.println("配置加载");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(reqInterceptor)
        /*
        自己new出来的只是一个普通的对象->不能用到IOC，DI这些，就只能拿到null
        Spring帮我们new的对象->能用到IOC，DI,会自动加入我们的各级依赖
         */
//        registry.addInterceptor(new ReqInterceptor())
                // localhost:8080/admin -> /*
                // localhost:8080/demo/index -> /**
                .addPathPatterns("/**");
    }
}
